package com.loong.user.handler;

import com.loong.common.domain.BaseQuery;
import com.loong.common.domain.Pager;
import com.loong.common.utils.TransformUtils;
import com.loong.user.business.ManageApiBusiness;
import com.loong.user.common.backend.param.ManageApiParam;
import com.loong.user.common.backend.param.ManageApiQueryParam;
import com.loong.user.common.backend.result.ManageApiResult;
import com.loong.user.model.ManageApi;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * @Description: 后台api管理
 * @Author: hzp
 * @Date: 2020-10-16 10:27
 */
@Component
public class ManageApiHandler {
    @Resource
    private ManageApiBusiness manageApiBusiness;

    /**
     * 保存后台api
     * @param param
     */
    public void save(ManageApiParam param){
        manageApiBusiness.save(TransformUtils.transform(param, ManageApi.class));
    }

    /**
     * 更新后台api
     * @param param
     */
    public void update(ManageApiParam param){
        manageApiBusiness.updateByPrimaryKeySelective(TransformUtils.transform(param, ManageApi.class));
    }

    /**
     *根据id删除后台api
     * @param id 用户的id
     */
    public void deleteById(Long id){
        manageApiBusiness.deleteById(id);
    }

    /**
     * 分页查询
     * @param baseQuery
     * @param param
     * @return
     */
    public Pager<ManageApiResult> pageQuery(BaseQuery baseQuery, ManageApiQueryParam param){
        Pager<ManageApi> manageApisPager = manageApiBusiness.pageQuery(baseQuery, () -> manageApiBusiness.query(param));
        return TransformUtils.transformPage(manageApisPager, ManageApiResult.class);
    }


}
